﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class persona_wfAddPerson : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string ccar = Request.QueryString["ccar"];
        
        if (!Page.IsPostBack)
        {
            ListItem lst = new ListItem();
            lst.Text = "Seleccione";
            lst.Value = "99999";

            HHo_Negocio.GestorQA oQA = new HHo_Negocio.GestorQA();

            ddlCargo.DataSource = oQA.ListarCargos();
            ddlCargo.DataTextField = "CargoDescripcion";
            ddlCargo.DataValueField = "CargoCodigo";
            ddlCargo.DataBind();
            ddlCargo.Items.Add(lst);
            if (ccar != null)
                ddlCargo.SelectedValue = ccar;
            else
                ddlCargo.SelectedValue = "99999";

            ListItem lstItem = new ListItem();
            lstItem.Text = "Seleccione";
            lstItem.Value = "99999";

            HHo_Negocio.GestorPMS oPMS = new HHo_Negocio.GestorPMS();
            ddlFlota.DataSource = oPMS.ListarFlotas();
            ddlFlota.DataTextField = "Descripcion";
            ddlFlota.DataValueField = "Codigo";
            ddlFlota.DataBind();
            ddlFlota.Items.Add(lstItem);
            ddlFlota.SelectedValue = "2"; //correspondiente a flota A319
            //ddlFlota.SelectedValue= "99999";

            PoblarGrid();
        }
    }
    

    private void PoblarGrid()
    {
        HHo_Negocio.GestorQA oQA = new HHo_Negocio.GestorQA();
        gvTrab.DataSource = oQA.ConsultarPersonasQA(Int32.Parse(ddlCargo.SelectedValue),Int32.Parse(ddlFlota.SelectedValue), txtApPat.Text);
        gvTrab.DataBind();
    }

    //private void PoblarGrid(int CodCar, int IdFlo)
    //{
    //    HHo_Negocio.GestorQA oQA = new HHo_Negocio.GestorQA();
    //    gvTrab.DataSource = oQA.ConsultarPersonasQA(CodCar,IdFlo);
    //    gvTrab.DataBind();
    //}

    protected void gvTrab_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string ctrl = Request.QueryString["ctrl"];
        
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Display the company name in italics.
            //e.Row.Cells[6].Text = "<input type='radio' name='opcion' value='" + e.Row.Cells[0].Text + "' onclick='window.opener.document.getElementById ('" + ctrl + "').value = '" + e.Row.Cells[0].Text + "';self.close() />";//Seleccionar
            //e.Row.Cells[6].Text = "<input type=\"radio\" name=\"opcion\" value=\"" + e.Row.Cells[0].Text + "\" onclick=\"window.opener.document.getElementById ('" + ctrl + "').value = '" + e.Row.Cells[1].Text +","+ e.Row.Cells[2].Text +","+ e.Row.Cells[3].Text +","+ e.Row.Cells[0].Text + "\';self.close()\" />";//Seleccionar
            if(Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem,"EsHabilitado")) == true)
                e.Row.Cells[6].Text = "<img src=\"../styles/a-main/verde.gif\" onclick=\"window.opener.document.getElementById ('" + ctrl + "').value = '" + e.Row.Cells[1].Text + "," + e.Row.Cells[2].Text + "," + e.Row.Cells[3].Text + "," + e.Row.Cells[0].Text + "\';self.close()\" />";
            else
                e.Row.Cells[6].Text = "<img src=\"../styles/a-main/Apagado.gif\" onclick=\"window.opener.document.getElementById ('" + ctrl + "').value = '" + e.Row.Cells[1].Text + "," + e.Row.Cells[2].Text + "," + e.Row.Cells[3].Text + "," + e.Row.Cells[0].Text + "\';self.close()\" />";
        }

    }

    protected void gvTrab_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvTrab.PageIndex = e.NewPageIndex;
        PoblarGrid();
    }
    protected void imgConsultar_Click(object sender, ImageClickEventArgs e)
    {
        PoblarGrid();
    }
}
